package com.czr.config.mvc;

import com.czr.handler.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Description:
 * Author: czr czr
 * Version: 1.0
 * Create Date Time: 2021/11/23 15:47.
 * Update Date Time:
 *
 * @see
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    // 把拦截器放入ioc容器中
    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    // 注册拦截器方法吧
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor())
                // 进行拦截
                .addPathPatterns("/","/index","blog/**","comon/**","/api/**","/blog/**");
                // 排除指定路径  不进行拦截
                //.excludePathPatterns("/api/new/**");
    }
}
